import { createRouter, createWebHistory } from "vue-router";

const routes = [
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login/login.vue"), // 页面引入方法二
  },
  {
    path: "/teleport",
    name: "teleport",
    component: () => import("@/views/teleportTest.vue"), // 页面引入方法二
  },
];

// 批量引入模块页面路由 引入值是对象
const moduleFiles = require.context("./modules", true, /\.js$/);
moduleFiles.keys().forEach((modulePath) => {
  routes.push(moduleFiles(modulePath).default);
});
// 共通路由  引入值是数组
const commonFiles = require.context("./common", true, /\.js$/);
commonFiles.keys().forEach((modulePath) => {
  routes.push(...commonFiles(modulePath).default);
});

const router = createRouter({
  mode: "history",
  history: createWebHistory(),
  routes,
});

// 根据路由配置信息中的标题，来进行浏览器标签页的标题切换
// router.beforeEach((to, from, next) => {
//   to.meta.title && (document.title = to.meta.title);
//   next();
// });

export default router;
